package entity

import (
	"encoding/json"
	"gorm.io/gorm"
	"time"
)

type TaskRecord struct {
	TaskID        int             `gorm:"primaryKey;autoIncrement" json:"task_id"`
	AppName       string          `gorm:"type:varchar(255);not null" json:"app_name"`
	CiBuildID     int             `gorm:"default:0" json:"ci_build_id"`
	CdBuildID     int             `gorm:"default:0" json:"cd_build_id"`
	PipelineParam json.RawMessage `gorm:"type:json;default:null" json:"pipeline_param"`
	Status        string          `gorm:"type:varchar(100);default:init" json:"status"`
	Message       string          `gorm:"type:varchar(255);default:NULL" json:"message"`
	CiJobName     string          `gorm:"type:varchar(100);default:NULL" json:"ci_job_name"`
	CdJobName     string          `gorm:"type:varchar(100);default:NULL" json:"cd_job_name"`
	AutoDeploy    bool            `gorm:"type:tinyint(1);default:1" json:"auto_deploy"`
	Products      string          `gorm:"type:varchar(255);default:NULL" json:"products"`
	CreatedAt     time.Time       `gorm:"type:timestamp;not null;default:CURRENT_TIMESTAMP" json:"created_at"`
	UpdatedAt     time.Time       `gorm:"type:timestamp;not null;default:CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP" json:"updated_at"`
	DeletedAt     gorm.DeletedAt  `gorm:"index" json:"deleted_at"`
}

func (t TaskRecord) TableName() string {
	return "task_record"
}
